
import numpy


class NumpyManager(object):
    """
    numpy管理器
    """

    def __init__(self, array):
        self.numpy_ndarray = numpy.array(array)

    def all_zeros(self):
        print(numpy.zeros((10, 5)))

    def array_property(self):
        """
        array的属性
        :return:
        """
        print("===========array_property=====================")
        print(f"ndarray.shape : {self.numpy_ndarray.shape}")
        print(f"ndarray.ndim : {self.numpy_ndarray.ndim}")
        print(f"ndarray.size : {self.numpy_ndarray.size}")
        print(f"ndarray.itemsize : {self.numpy_ndarray.itemsize}")
        print(f"ndarray.dtype : {self.numpy_ndarray.dtype}")
        print("===========array_property=====================")

    @staticmethod
    def array_add():
        """
        数组相加
        :return:
        """
        print("===========array_add=====================")
        array_1 = numpy.array([[1, 2, 3, 4], [5, 6, 7, 8]])
        array_2 = numpy.array([[1], [5]])
        print(array_1 + array_2)
        print(array_1 + 2)
        print("===========array_add=====================")

    @staticmethod
    def array_multiply():
        """
        乘法
        :return:
        """
        print("===========array_multiply=====================")
        print(numpy.dot(numpy.array([[1, 2, 3, 4], [5, 6, 7, 8]]), numpy.array([[1, 2], [3, 4], [5, 6], [7, 8]])))

        print(numpy.matmul(numpy.array([[1, 2, 3, 4], [5, 6, 7, 8]]), numpy.array([[1, 2], [3, 4], [5, 6], [7, 8]])))
        print(numpy.dot(numpy.array([[1, 2, 3, 4], [5, 6, 7, 8]]), 3))
        print("===========array_multiply=====================")


if __name__ == '__main__':
    # print(numpy.random.uniform(1, 100, 11))
    numpy_manager = NumpyManager([[1, 2, 3, 4], [5, 6, 7, 8]])
    numpy_manager.array_property()
    numpy_manager.array_add()
    numpy_manager.array_multiply()
